<?php
namespace app\bis\controller;


class Baseinfo extends Base{

    public function index()
    {
        $bisId=$this->getLoginUser()->bis_id;
        $bis=model('bis')->get(['id'=>$bisId]);
        $citys = model('City')->getNormalCitysByParentId();
        return $this->fetch('',[
            'bis'=>$bis,
            'citys'=> $citys]);
    }

    public function update(){
        // 获取表单的值
        $data = input('post.');
        //检验数据
        $validate = validate('Bis');
        if(!$validate->scene('add')->check($data)) {
            $this->error($validate->getError());
        }

        // 判定提交的用户是否存在
        $accountResult = model('Bis')->get(['name'=>$data['name']]);
        if($accountResult) {
            $this->error('该商户存在，请重新分配');
        }
        // 商户基本信息入库
        $bisData = [
            'name' => $data['name'],
            'city_id' => $data['city_id'],
            'city_path' => empty($data['se_city_id']) ? $data['city_id'] : $data['city_id'].','.$data['se_city_id'],
            'logo' => $data['logo'],
            'licence_logo' => $data['licence_logo'],
            'description' => empty($data['description']) ? '' : $data['description'],
            'bank_info' =>  $data['bank_info'],
            'bank_user' =>  $data['bank_user'],
            'bank_name' =>  $data['bank_name'],
            'faren' =>  $data['faren'],
            'faren_tel' =>  $data['faren_tel'],
            'email' =>  $data['email'],
            'status' => 0,
        ];
        $bisId = model('Bis')->save($bisData,['id'=>intval($data['id'])]);
        if ($bisId){
            $this->success('更新成功', url('location/index'));
        }else{
            $this->error('更新失败');
        }
    }
}